package com.shardingsphere.modules.controller;

import com.shardingsphere.modules.entity.Teacher;
import com.shardingsphere.modules.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "教室管理")
@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Resource
    private TeacherService teacherService;

    @ApiOperation(value = "新增老师")
    @PostMapping("/add")
    public String add(@RequestBody Teacher teacher) {
        return teacherService.save(teacher) ? "添加成功" : "添加失败";
    }

    @ApiOperation("删除老师")
    @DeleteMapping("/delete/{id}")
    public String delete(@ApiParam("老师的主键id") @PathVariable(value = "id") Integer id) {
        return teacherService.removeById(id) ? "删除成功" : "删除失败";
    }

    @ApiOperation("修改老师")
    @PostMapping("/update")
    public String update(@RequestBody Teacher teacher) {
        return teacherService.updateById(teacher) ? "修改成功" : "修改失败";
    }

    @ApiOperation(value = "查询老师")
    @GetMapping("/list")
    public List<Teacher> list(){
        return teacherService.selectList();
    }

}
